import { useState } from "react"

let timer: NodeJS.Timeout | null
export const useFontSize = () => {
  const [fontSize, setFontSize] = useState(0)
  const [screenWidth, setScreenWidth] = useState(0)
  window.addEventListener("resize", () => {
    fun()
  })
  window.addEventListener("load", () => {
    fun()
  })
  const fun = () => {
    const sWidth = document.documentElement.clientWidth
    setScreenWidth(sWidth)
    const fSize = sWidth / 50 > 30 ? 30 : sWidth / 50 < 14 ? 14 : sWidth / 50
    setFontSize(fSize)
    document.documentElement.style.fontSize = fSize + "px"
  }

  return { fontSize, screenWidth, fun }
}
